<template>
  <div class="app-container">
    <eHeader :query="query" />
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;">
      <!--
      <el-table-column prop="startTime" :show-overflow-tooltip="true" label="发起时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime) }}</span>
        </template>
      </el-table-column>-->
      <el-table-column prop="startTime" :show-overflow-tooltip="true" label="工单编号">
        <template slot-scope="scope">
          <span>{{ scope.row.order.orderCode }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="customerName" :show-overflow-tooltip="true" label="客户名称" />
      <el-table-column prop="taskTitle" :show-overflow-tooltip="true" label="任务名称" />
      <el-table-column prop="taskContent" :show-overflow-tooltip="true" label="任务内容" />
      <el-table-column prop="taskAddr" :show-overflow-tooltip="true" label="详细地址" />
      <!-- <el-table-column prop="attachments" label="附件"/>-->
      <el-table-column prop="arriveTime" :show-overflow-tooltip="true" label="要求到场时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.arriveTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="finishTime" :show-overflow-tooltip="true" label="要求完成时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finishTime) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="notes" label="备注"/>-->
      <el-table-column prop="linker" :show-overflow-tooltip="true" label="联系人" />
      <el-table-column prop="cellphone" :show-overflow-tooltip="true" label="联系电话" />
      <el-table-column prop="inputOperator" :show-overflow-tooltip="true" label="录入人" />
      <el-table-column prop="inputTime" :show-overflow-tooltip="true" label="录入时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inputTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="checkPermission(['ADMIN','TTASKS_ALL','TTASKS_EDIT','TTASKS_DELETE'])" fixed="right" label="操作" width="150px" align="center">
        <template slot-scope="scope">
          <assign-order v-show="scope.row.order.status == 100" v-permission="['ADMIN','TACCIDENT_ALL','TACCIDENT_EDIT']" :data="scope.row" :sup-this="supThis" :is-view="false" />
          <assign-order v-show="scope.row.order.status > 100" v-permission="['ADMIN','TACCIDENT_ALL','TACCIDENT_EDIT']" :data="scope.row" :sup-this="supThis" :is-view="true" />
          <edit
            v-permission="['ADMIN','TTASKS_ALL','TTASKS_EDIT']"
            :data="scope.row"
            :sup-this="supThis"
            :is-view="scope.row.order.status !== 100"
          />
          <!-- <el-popover
            v-permission="['ADMIN','TTASKS_ALL','TTASKS_DELETE']"
            :ref="scope.row.id"
            placement="top"
            width="180">
            <p>确定删除本条数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定</el-button>
            </div>
            <el-button v-show="scope.row.order.status === 100" slot="reference" type="text" size="mini">删除</el-button>
          </el-popover> -->
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"
    />
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { del } from '@/api/tTasks'
import { parseTime } from '@/utils/index'
import eHeader from './module/header'
import edit from './module/edit'
import AssignOrder from './module/assignOrder'
export default {
  components: { eHeader, edit, AssignOrder },
  mixins: [initData],
  data() {
    return {
      delLoading: false,
      supThis: this
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    parseTime,
    checkPermission,
    beforeInit() {
      this.url = 'api/tTasks'
      const sort = ['id,desc', 'state,asc']
      this.params = { page: this.page, size: this.size, sort: sort }
      const query = this.query
      if (query.customerName) {
        this.params['customerName'] = query.customerName
      }
      if (query.taskAddr) {
        this.params['taskAddr'] = query.taskAddr
      }
      if (query.inputOperator) {
        this.params['inputOperator'] = query.inputOperator
      }
      return true
    },
    subDelete(id) {
      this.delLoading = true
      del(id).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.init()
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 2500
        })
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err)
      })
    }
  }
}
</script>

<style scoped>

</style>
